<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.pro.bean.*"%>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>所有部门信息</title>

	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>css/bootstrap.css">
	<script type="text/javascript" src="<%=basePath%>js/bootstrap.js"></script>
	<script type="text/javascript">
		function check()
		{
			if(document.searchform.cname.value=="")
    		{
  				alert("部门名称不能为空！");
    			document.searchform.cname.focus();
   		 		return false;
    		}
		}
	</script>
  </head>
  
  <body>
  <%
		ArrayList list=(ArrayList)session.getAttribute("list");
		Iterator it=list.iterator(); 
		 int intPageSize=6;  //每页显示的记录数
			int currPageBegin;  //起始记录索引	
			int AllPage;   //总页数
			int requestPage;     //用户请求页码
			String strPage;
			
			strPage=request.getParameter("pagenumber");
			 if(strPage==null)
			 {
			 requestPage=1;
			 }
			 else
			 {
			    requestPage=Integer.parseInt(strPage);
			    if(requestPage<1)
			   {
			    requestPage=1;
			    }
			 
			 }
			 AllPage=(list.size()+intPageSize-1)/intPageSize;
			 if(requestPage>AllPage)
			    requestPage=AllPage;
			currPageBegin=requestPage*intPageSize-intPageSize;	
			
		  
			if(list == null||list.size()==0)
				out.println("组为空");


		//System.out.println(list.size());
		%>

    	<form name="searchform" action="<%=basePath%>servlet/SearchCmpServlet" method="post" onsubmit="return check()">
    		<table border="0" align="center">
    			<tr>
    				<td>请输入需要查找的部门名称：</td>
    				<td><input type="text" name="cname"></td>
    				<td><button type="submit" class="btn btn-primary" onclick="submit">提交</button></td>
    			</tr>
    		</table>
    	</form>
    	
    		<table width="50%" align="center">
    			<tr>
   					 <td>
   						 <fieldset style="height: 100%;">
						<legend>
							<font color="#FF0000" size="2">检索结果共<%=list.size() %>件</font>
						</legend>
						<table class="table table-bordered table-hover" align="right">
    						<caption>所有部门信息</caption>
							<tr class="success">
								<td align="center">部门编号</td>
								<td align="center">部门名称</td>
								<td></td>
							</tr>
		
				<%
				
				for(int i=currPageBegin; i < requestPage*intPageSize&&i<list.size();i++){
			 
//				while(it.hasNext()){

//					Unit unit=(Unit)it.next();
					//System.out.println("unit.getUnitname"+unit.getUnitname());			
				 %>
							<tr class="active">
								<td align="center"><%=((Unit)list.get(i)).getUnitid() %></td>
								<td align="center"> <%=((Unit)list.get(i)).getUnitname() %></td>
								<td><table align="center"><tr>
								<td>
									<a href="<%=basePath%>servlet/EditCmpServlet?
										unitId=<%=((Unit)list.get(i)).getUnitid() %>&
										unitname=<%=((Unit)list.get(i)).getUnitname() %>
										">
									编辑</a>
								</td>
								<td>
									<a href="<%=basePath%>servlet/DelCmpServlet?unitId=<%=((Unit)list.get(i)).getUnitid() %>">删除</a>
								</td></tr></table>
								</td>
							</tr>				
				<%} %>
						</table>
						</fieldset>
   					 </td>
    			</tr>
   			 </table>
    		<table>
    			<tr>
    			<td width="30%" align="right">
    			<center>
                               共<%=AllPage%>页&nbsp;第<%=requestPage%>页        
          <%if(requestPage>1){ %>
            <a href="<%=basePath %>gxr/admin_super_cmp_view.jsp?pagenumber=<%=requestPage-1%>">上一页</a>
            <%}else{ %>
                                    上一页
         <%}%>
         <%if(requestPage<AllPage){ %>
        <a href="<%=basePath %>gxr/admin_super_cmp_view.jsp?pagenumber=<%=requestPage+1%>">下一页</a>
            <%}else{ %>
                                   下一页
         <%}%>
         </center>    
    			
    			</td>
    			</tr>
    				
    		</table>
  

  </body>
</html>
